package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 报表管理
 */
@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ProductService productService;

    /**
     * 上下架商品数量统计
     */
    @GetMapping("/productUpOrDown")
    public Result productUpOrDown() {
        // 统计上架商品数量
        Integer upCount = productService.countByPublishStatus(1);
        
        // 统计下架商品数量
        Integer downCount = productService.countByPublishStatus(0);

        List<Map<String, Object>> data = new ArrayList<>();
        Map<String, Object> upMap = new HashMap<>();
        upMap.put("name", "上架");
        upMap.put("value", upCount);
        data.add(upMap);
        
        Map<String, Object> downMap = new HashMap<>();
        downMap.put("name", "下架");
        downMap.put("value", downCount);
        data.add(downMap);
        
        return Result.success(data);
    }
    @GetMapping("/productStatus")
    public Result productStatus() {
        // 统计审核通过商品
        List<Map> productStatus = productService.productStatus();

        return Result.success(productStatus);
    }
}
